<template>
  <div class="app-container">
    <ul class="tabTitle">
      <li>基本信息</li>
      <el-button
        type="primary"
        size="medium"
        class="dialog-footer"
        @click="preservation"
        >保存</el-button
      >
      <el-button size="medium" class="dialog-footers" @click="gocancel"
        >取消</el-button
      >
    </ul>
    <div class="viewformcolumn">
      <el-form
        :model="queryParams"
        :rules="rules"
        ref="queryForm"
        label-width="200px"
        size="medium"
        :inline="true"
      >
        <!-- label="数据源名" -->
        <el-form-item prop="dataSourceName" :style="{ width: '96%' }">
          <!-- <el-input
          v-model="queryParams.dataSourceName"
          placeholder="请输入数据源名称"
          clearable
        /> -->
          <el-input
            placeholder="请输入数据源名称"
            v-model="queryParams.dataSourceName"
          >
            <template slot="prepend">数据源名</template>
          </el-input>
        </el-form-item>
        <!-- label="图标" -->
        <el-form-item class="fromList2" :style="{ width: '46.7%' }">
          <el-input>
            <template slot="prepend">图标</template>
            <template slot="append">
              <el-upload
                class="add-upload"
                ref="add-upload"
                drag
                action
                multiple
                :auto-upload="false"
                :limit="1"
                :on-exceed="handleExceed"
                :on-change="handleChange"
              >
                <i class="el-icon-plus">上传文件</i>
              </el-upload>
            </template>
          </el-input>
        </el-form-item>
        <!-- label="插件" -->
        <el-form-item class="fromList2" :style="{ width: '46.7%' }">
          <el-input>
            <template slot="prepend">插件</template>
            <template slot="append">
              <el-upload
                class="add-upload"
                ref="add-upload"
                drag
                action
                multiple
                :auto-upload="false"
                :limit="1"
                :on-exceed="handleExceed"
                :on-change="handleChange"
              >
                <i class="el-icon-plus">上传文件</i>
              </el-upload>
            </template>
          </el-input>
        </el-form-item>

        <el-form-item :style="{ width: '96%' }" class="fromList3">
          <el-input>
            <template slot="prepend">描述</template>
            <template slot="append">
              <el-input
                v-model="queryParams.dataSourceComment"
                type="textarea"
                placeholder="请输入描述"
                :autosize="{ minRows: 14, maxRows: 14 }"
                prop="dataSourceComment"
              >
              </el-input>
            </template>
          </el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { add } from "@/api/metadata/datasource";
export default {
  name: "newdatasource",
  data() {
    return {
      //基本信息的表内容
      queryParams: {
        dataSourceName: "", //数据源名
        imageUrl: "", //图标url
        dataSourceComment: "", //描述
        pluginUrl: "", //插件URL
        creationTime: "", //创建时间
        dataSourceId: "", //数据源主键id
        isDel: 0, //逻辑删除
        isLock: 0, //锁定
        isConfig: 0, //是否配置
        password: "", //密码
        userName: "", //用户名
        url: "", //链接url
      },
      rules: {
        dataSourceName: [
          { required: true, message: "数据源名称不能为空", trigger: "blur" },
        ],
        dataSourceComment: [
          { required: true, message: "描述不能为空", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    //保存
    preservation() {
      add(this.queryParams)
        .then((response) => {
          if (response.success) {
            this.$message.success("新增成功");
            this.resetForm("queryForm");
            this.$router.go(-1);
          }
        })
        .catch((err) => {
          // this.$message.error(err.message);
           console.log(err);
        });
    },
    //取消--清空表单
    gocancel() {
      this.queryParams.dataSourceName = "";
      this.queryParams.dataSourceComment = "";
    },
    // 文件上传数量判断
    handleExceed(e) {
      this.$message({
        type: "warning",
        message: "只能上传一个文件!",
      });
    },
    // 文件格式判断
    handleChange(file, fileList) {
      // if (!/\.(xlsx|xls|XLSX|XLS)$/.test(file.name)) {
      //   this.$message({
      //     type: 'warning',
      //     message: '上传文件只能为excel文件!'
      //   })
      //   this.fileList = []
      //   return false
      // }
      // this.file = file.raw // 手动上传需要保存 file.raw
    },
  },
};
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/mixin.scss";
@import "~@/assets/styles/variables.scss";
.app-container {
  background: #fff;
  height: 755px;
}
.tabTitle {
  font-size: 18px;
    list-style: none;
    height: 90px;
    padding: 30px 0;
    margin: 0 35px;
    border-bottom: 1px solid rgb(221, 218, 218);
}
.tabTitle li {
  float: left;
  line-height: 50px;
  text-align: center;
  border-radius: 5px;
  color: #919cb1;
}
.dialog-footer {
  float: right;
    width: 122px;
      height: 40px;
      background-color: $labelColor;
      color: #fff;
      font-size: 16px;
      border-color:#e8eaec ;
      border-radius:4px ;
}
.dialog-footers {
  float: right;
  width: 122px;
  height: 40px;
  background-color: #fff;
  color: $labelColor;
  font-size: 16px; 
  border-color:#e8eaec ;
  border-radius:4px ;
  margin-right: 10px;
}

  .el-form-item {
    margin: 30px 0 0 30px;
  }
.el-icon-plus {
  margin: 0 auto;
}
::v-deep .el-input-group__append {
  background: #fff;
  border-left: 1px solid #dfe5f0;
}
::v-deep .fromList2 .el-form-item__content {
  width: 100%;
}
::v-deep .fromList2 .el-input-group__append .add-upload {
  height: 80px;
  background: #fff;
}
::v-deep .fromList2 .el-input-group__append {
  width: calc((100% - 140px) / 2);
  padding: 0;
}
::v-deep .fromList2 .el-upload-dragger {
  height: 80px;
  border: none;
  line-height: 80px;
}
::v-deep .fromList3 .el-input__inner {
  display: none;
}

::v-deep .fromList3 .el-form-item__content {
  width: 100%;
}
::v-deep .fromList3 .el-input-group__prepend {
  width: 120px;
}

::v-deep .fromList3 .el-input-group__append {
  width: calc(100% - 120px);
  padding: 0;
}
::v-deep .fromList3 .el-textarea__inner {
  border: none;
}
</style>
<style  scoped>
::v-deep .viewformcolumn .el-input-group__prepend {
  width: 100px;
}

::v-deep .viewformcolumn .el-form-item--medium .el-form-item__content {
  width: 100%;
}

::v-deep .viewformcolumn .el-input__inner {
  height: 80px;
}
::v-deep .viewformcolumn .fromList3 .el-input__inner {
  display: none;
}
::v-deep .viewformcolumn .fromList2 .el-input__inner {
  display: none;
}
::v-deep .viewformcolumn .fromList3 .el-input-group__prepend {
  width: 100px;
}
::v-deep .viewformcolumn .fromList3 .el-input-group__append {
  width: calc(100% - 100px) !important;
  padding: 0;
  border-left: 1px solid #e4e7ed;
}
::v-deep .viewformcolumn .fromList3 .el-textarea__inner {
  border: none;
}
</style>
